/**
 * create by young (young2f@outlook.com) on 2020/12/4
 * 采购物料记录
 */
'use strict';
const model = require('../base/tModelBase');
const _ = require('lodash');
module.exports = app => {
  const mongoose = app.mongoose;
  const schema = mongoose.Schema;
  const connect = app.mongooseDB.get('pmcBus');
  const json = {
    salesOrderCode: { type: String, _type: 'string', title: '单编码', enableArea: [ 'table',  'search'], },
    division: { type: String, _type: 'string', title: '事业部', enableArea: [ 'table',  'search'], },
    customer: { type: String, _type: 'string', title: '客户', enableArea: [ 'table',  'search'], },
    pLotId: { type: String, _type: 'string', title: '采购物料批次编码', required: true },
    prodCode: { type: String, _type: 'string', title: '编码', required: true },
    prodName: {  type: 'string', inputType: 'string', title: '品名', enableArea: [ 'table', 'input', 'detail', ],  },
    count: { type: Number, _type: 'number', title: '采购数量', enableArea: [ 'table',  'search'], },
    price: { type: Number, _type: 'number', title: '单价', enableArea: [ 'table',  'search'], },
    pkgFee: { type: Number, _type: 'number', title: '单价', enableArea: [ 'table',  'search'], },
    laborFee: { type: Number, _type: 'number', title: '单价', enableArea: [ 'table',  'search'], },
    taxDeductionPointForLaborCosts: { type: Number, _type: 'number', title: '单价', enableArea: [ 'table',  'search'], },
    needInvoice: {  type: 'string', inputType: 'string', title: '编号', enableArea: [ 'table', 'input', 'detail', ],  },
    deliverWay: {  type: 'string', inputType: 'string', title: '编号', enableArea: [ 'table', 'input', 'detail', ],  },
    pkg: {  type: 'string', inputType: 'string', title: '编号', enableArea: [ 'table', 'input', 'detail', ],  },
    label: {  type: 'string', inputType: 'string', title: '编号', enableArea: [ 'table', 'input', 'detail', ],  },
    invoicingDate: {  type: 'date', inputType: 'date', title: '开票时间', enableArea: [ 'table', 'input', 'detail', ],  },
    materials: {  type: 'array', inputType: 'array', title: '编号', enableArea: [ 'table', 'input', 'detail', ],  },
    fileList: { type: Array, _type: 'array', title: '附件', enableArea: [ 'table',  'search'] },
  };
  const _model = _.cloneDeep(model);
  _.assign(_model, json);
  const _schema = new schema(
    _model,
    { timestamps: { createdAt: 'createdTs', updatedAt: 'updatedTs' } }
  );
  return connect.model('SalesProdRecord', _schema);
};
